[Unit]
Description=etcd
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
ExecStart={{ etcd_link_path }}/etcd \
        --name etcd-server-{{ localip.stdout.split('.')[2:] | join('-') }} \
        --enable-v2 \
        --data-dir /data/etcd/etcd-server \
        --listen-peer-urls https://{{ localip.stdout }}:2380 \
        --listen-client-urls https://{{ localip.stdout }}:2379,http://127.0.0.1:2379 \
        --quota-backend-bytes 8000000000 \
        --initial-advertise-peer-urls https://{{ localip.stdout }}:2380 \
        --advertise-client-urls https://{{ localip.stdout }}:2379,http://127.0.0.1:2379 \
        --initial-cluster {% for item in  play_hosts %}etcd-server-{{ item.split('.')[2:]|join('-') }}=https://{{ item }}:2380{% if not loop.last %},{% endif %}{% endfor %} \
        --cert-file {{ etcd_link_path }}/certs/etcd-peer.pem \
        --key-file {{ etcd_link_path }}/certs/etcd-peer-key.pem \
        --client-cert-auth \
        --trusted-ca-file {{ etcd_link_path }}/certs/ca.pem \
        --peer-cert-file {{ etcd_link_path }}/certs/etcd-peer.pem \
        --peer-key-file {{ etcd_link_path }}/certs/etcd-peer-key.pem \
        --peer-client-cert-auth \
        --peer-trusted-ca-file {{ etcd_link_path }}/certs/ca.pem \
        --log-output stdout
Restart=on-failure
LimitNOFILE=65536
RestartSec=1

[Install]
WantedBy=multi-user.target
